package com.ssyx.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssyx.common.result.Result;
import com.ssyx.home.service.HomeService;
import com.ssyx.model.product.Category;
import com.ssyx.model.product.SkuInfo;
import com.ssyx.vo.search.SkuEsQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName:CategoryApiController
 * Description:
 *
 * @Author kay
 * @Create 2024/5/16 10:47
 * @Version 1.0
 */
@Tag(name = "商品分类")
@RestController
@RequestMapping("api/home")
public class CategoryApiController {

    @Autowired
    private HomeService homeService;

    @Operation(summary = "获取分类信息")
    @GetMapping("category")
    public Result index() {
       List<Category> categoryList = homeService.getAllcategoryList();
       return Result.ok(categoryList);
    }

    //此方法应该在ES中上架的商品中搜索,但是ES使用不了
    //改成,在sku_info表的上架商品中搜索
    @Operation(summary = "分类列表中搜索商品")
    @GetMapping("/search/sku/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       SkuEsQueryVo skuEsQueryVo) {

        Page<SkuInfo> pageModel = homeService.getPage(page,limit,skuEsQueryVo);
        return Result.ok(pageModel);
    }
}
